<?php
/**
 * @author Garry
 *
 *
 */
abstract class ContentDao extends Dao {

	public $test = 8;
	

	function __construct( $action = FALSE ) {
		
		$this->property_types = array_merge_recursive(
		$this->property_types,
		array(
                        'authorid' => array(
                                                 'type' => 'INT',
                                                 'constraint' => 5,
												 'default' => 0
                                          ),
                        'content_id' => array(
                                                 'type' => 'VARCHAR',
                                                 'constraint' => 30,
                                          		 'null' => TRUE
                                          ),
                       'content' => array(
                                                 'type' => 'TEXT',
                                          		 'null' => TRUE
                                          ),
                       'publishable' => array(
                                                 'type' => 'BIT',
                                          		 'null' => TRUE
                                          ),
                       'lastupdate' => array('type' => "TIMESTAMP DEFAULT CURRENT_TIMESTAMP")  
                         
                )
		);
		parent::__construct( $action );
	}
	/**
	 * 
	 * Return the editing component
	 */
	abstract public function GetEditorDisplay();
	/**
	 * 
	 * Get the view that will be seen if the edit mode is on
	 */
	public function GetEditableDisplay( $section_type="",$content=NULL ){
		$display = new Display();
		$display->base = "ContentDaoTemplates/editable_section";
		$publishaction = "publish_".$this->content_id."_$this->oid";
		$editaction = "edit_".$this->content_id."_$this->oid";
		$publish_btn = new ToggleButton($this->oid."_publish_btn",'images/icons/publish_button.png','','$("#'.$publishaction.'").submit()','images/icons/publish_button_over.png','cm_control_btn','Click this button to publish this section',$this->publishable);
		$publish_btn->finalize();
		$edit_btn = new ImageButton($this->oid."_edit_btn",'images/icons/edit_button.png','','$("#'.$editaction.'").submit()','images/icons/edit_button_over.png','cm_control_btn','Click this button to edit this section');
		$edit_btn->finalize();
		$delaction = "delete_".$this->content_id."_$this->oid";
		$del_btn = new ImageButton($this->oid."_del_btn",'images/icons/delete_button.png','','openDialog("Confirm Action","This will delete this section. \n Are you sure this is what you want to do?",true,function(){$("#'.$delaction.'").submit();})','images/icons/delete_button_over.png','cm_control_btn','Click this button to delete this section');
		$del_btn->finalize();
		if( $this->publishable ){
			$display->published = "published";
		}
		$display->section_type = $section_type;
		$display->content_editor_class = get_class( $this );
		$display->publish_url = "edit/publish/$this->oid/";
		$display->edit_url = "edit/editContent/$this->oid/";
		$display->del_url = "edit/deleteContent/$this->oid/";
		$display->publish_btn = $publish_btn->output;
		$display->edit_btn = $edit_btn->output;
		$display->del_btn = $del_btn->output;
		if( !empty($content) ){
			$display->content_section = $content;
		}
		else {
			$display->content_section = $this->content;
		}
		$display->id = $this->oid;
		$display->contentid = $this->content_id;
		$display->finalize();
		return $display;
	}

	/**
	 * 
	 * get the content for the section to view on the site
	 */
	public function GetDisplay(){
		if( (bool)$this->publishable ){
			return $this->content;
		}
		return "";
	}
}


?>